# print(5//2)#2
# print(5/2)#2.5
# if "True":#无论”“里面写什么，只要有东西系统就认为是true
#     print(1)
# else:
#     print(2)
##结果是1
# if "False":#无论”“里面写什么，只要有东西系统就认为是true
#     print(1)
# else:
#     print(2)
# ##结果是1
# if "":#无论”“里面写什么，只要有东西系统就认为是true，没有就是False
#     print(1)
# else:
#     print(2)
# ##结果是2
# if 0:
#     print(False)
# else:
#     print(True)
# # 因为0在Python中被视为False，而非0的数被视为True。
# # 因此，if 0的条件为False，进入else分支，输出True。
#
# if 0:
#     print(True)
# else:
#     print(False)
# # 因为0在Python中被视为False，而非0的数被视为True。
# # 因此，if 0的条件为False，进入else分支，输出False。

# a="Hello world!"
# print(a.replace("H","j"))#a中的字母H换成j
# print(r"\n")

# Inheritance继承 is the capability of one class to derive or inherit the properties from another class.
# polymorphism多态 means the same function name (but different signatures) being used for different types
# Encapsulation封装  users can manipulate without having to know internal details

# year=2023
# class_name="software degree"
# print(year,class_name)
# print(year,",",class_name)
# print(year,"\n",class_name)#\n换行
#
# Qucik exercise 3: What if I need to print the path.
# C:\user\one\two. How to write the code
# print("C:\\user\\one\\two")

# num=int(input("please enter a number:"))
# print("the number you enter is "+ str(num))
#
# name=str(input("please input your name:"))
# print("your name is:"+name)

# code=input("please enter the code:")
# if code=="0620":
#     print("correct")
# else:
#     print("incorrect")

# code=input("please enter the code:")
# n="123"
# if code==n.zfill(5):#=00123
#     print("correct")
# else:
#     print("incorrect")

# code=input("please enter the code:")
# n="123"
# if code==n.zfill(5):#=00123
#     print("correct")
# else:
#     code2=input("incorrect please enter again")#❗漏了input
#     if code2==n.zfill(5):#=00123
#         print("hello")
#     else:
#         print("incrooect too")

# print(str(3.14))
# print(type(str(3.14)))

# attendence=90
# performance=80
# report=100
# project=70
# print(attendence*0.25+performance*0.1+report*0.3+project*0.5)
#
# s = "     Hello, World!       "
# print(s.strip())
#
# str = 'hello world'
# print(str.strip('heldo').strip())#strip删除字符串两边跟括号里指定的元素相同的元素，然后再删除空格
# #结果：wor
#
# s = "Hello, World!"
# print(s.replace("World","Aillee"))
#
# s = "Hello, World!"
# print(s.center(50,"'"))
#
# # example of short hand IF
# a=50
# b=1
# if a > b: print("a is greater than b")
#
# c=1
# d=10
# print("D") if d>c else print("A")

# example pf multiple else statements on the same line
# a = 330
# b = 330
# print("lin") if a > b else print("🐖") if a == b else print("B")
#
# # and："Both conditions are True'"'
# # or："At least one of the conditions is True
#
# a=int(input("1st:"))
# b=int(input("2st:"))
# c=int(input("3st:"))
# print("yes") if a+c>b and b+c>a and a+b>c else print("no")

# a=int(input("1st:"))
# b=int(input("2st:"))
# c=int(input("3st:"))
# print("yes" ) if a+c>b and b+c>a and a+b>c and a==b or b==c or a==c else print("no")

# a=int(input("1st:"))
# b=int(input("2st:"))
# c=int(input("3st:"))
# print("yes") if a**2+b**2==c**2 or a**2+c**2==b**2 or b**2+c**2==a**2 else print("no")

# fruits = ["apple", "banana", "cherry"]
# for x in fruits:
#     print(x)
#     if x=="banana":
#         break
##apple
##banana
# fruits = ["apple", "banana", "cherry"]
# for x in fruits:
#     if x=="banana":
#         break
#     print(x)
##apple
# fruits = ["apple", "banana", "cherry"]
# for x in fruits:
#     if x == "banana":
#         continue#❗跳过本次循环中剩余的语句，直接进入下一次循环的判断条件
#     print(x)
##apple
##cherry
# fruits = ["apple", "banana", "cherry"]
# for x in fruits:#取列表里的元素
#     for y in x:#取元素里的字母
#         if x == "banana":
#             break
#         print(y)
# # a
# # p
# # p
# # l
# # e
# # c
# # h
# # e
# # r
# # r
# # y

# fruits_list = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
# num=0
# for name in fruits_list:
#     if name=="kiwi":
#         break
#     print(num,name)
#     num+=1

# n=int(input("please input a number:"))
# sum=0
# for i in range(0,n,3):
#     sum+=i#这里是i，因为每一个sum都隔了3
# print(sum)
#
# x=0
# y=0
# z=0
# count=0
# for x in range(51):
#     for y in range(101):
#         for z in range(101):#101表示c鸡最多可买100只
#             if x+y+z==100 and 2*x+y+0.5*z<=100:
#                 print("A;",x,"B:",y,"C:",z)
#                 count+=1
# print(count)#计算一共有多少种方法

# sum=0
# for x in range(0,51):
#     sum+=x
# print(sum)

# for x in range(5):
#     print(f'00'+str(x))
# #000
# #001
# #002
# #003
# #004
# 计算平方：
# x = int(input("Please input an integer: "))#作用是提示用户输入一个整数，并将用户输入的整数赋值给变量x
# ans = 0#作用是初始化变量ans，用于后续的累加操作
# iterLeft = x#，作用是初始化变量iterLeft，记录还需要循环多少次
# while iterLeft != 0:#开始一个while循环，只要iterLeft不等于0，就一直循环下去
#     ans = ans + x#作用是将x累加到ans中
#     iterLeft = iterLeft - 1#作用是将iterLeft减1，以记录循环还需要执行多少次。
# print(str(x) + '*' + str(x) + '=' + str(ans))#使用print函数输出计算结果，其中str()函数用于将数字转换成字符串，"+"符号用于将多个字符串拼接在一起，
# 最终输出的字符串表示x的平方等于ans

# fruits=["a",'b','c']
# for x in fruits:
#     print(x)
#     if x=="b":
#         break
# #a
# #b
# fruits=["a",'b','c']
# for x in fruits:
#     if x=="b":
#         break
#     print(x)
# #a
# fruits=["a",'b','c']
# for x in fruits:
#     if x=="b":
#         continue
#     print(x)
#a
#c

#递归：自己调用自己的方式
# Suppose there is a monkey. He has a weird habit.
# After finish eating half of the peaches, He loves to eat one more peach every day.
# In day 10, there is only one peach left. What’s the total number of peaches in day 1?
# def f(d,rest):#这段代码实现了一个递归函数，用于求解一个人在第10次起床后，前9天每天都是前一天的两倍再加1，第10天起床后依然是前一天的两倍再加1，
# 问第1天起床后是第几次这样起床（即求逆推过程）。
#     if d == 1:
#         return rest
#     else:
#         return f(d-1, (rest+1)*2)
# print(f(10,1))
#
# def fact(n):
#     if n == 0:
#         return 1
#     else:
#         return n * fact(n - 1)
# print(fact(5))#计算5的阶乘---答案120

#检错
# try:
#     a = int(input("give me a number: "))
#     b = int(input("give me another number: "))
#     print("a/b = ", a / b)
#     print("a+b = ", a + b)
# except ZeroDivisionError:
#     print("We could not divide by 0.")
# except ValueError:
#     print("The input value cannot convert to number.")
# except:
#     print("Something wrong. Please check.")
# print("Outside")
# 静态语义错误print 不存在的东西
# eg
# print(hi)
# 由单元到整体测试
#
# 先随机测试，带几个数进去
#
# 测试方法包括两种：
# 1黑盒测试Black Box：不看代码设计的文字描述，可复用，需考虑边界条件
# 2白盒测试White（Glass） Box：除了看文字描述还要看代码，path-complete所有路径（工作）跑一遍
# 缺点：工作量大，复杂

# import math
# class Vector(object):
#
#     def __init__(self, x=0, y=0):
#         self.x = x
#         self.y = y
#
#     def __abs__(self):
#         return math.sqrt(self.x ** 2 + self.y ** 2)
#
#     def __add__(self, other):  # 自定义+
#         return (self.x + other.x, self.y + other.y)
#
#     def __mul__(self, other):  # 自定义*
#         return self.x * other.x + self.y * other.y
#
#     def __sub__(self, other):  # 自定义-
#         return (self.x - other.x, self.y - other.y)
#
#     def __truediv__(self, other):  # 自定义 /
#         return (self.x / other.x, self.y / other.y)
#
# A = Vector(1, 2)
# B = Vector(2, 1)
# print(A + B, A * B, A - B, A / B)
# #(3, 3) 4 (-1, 1) (0.5, 2.0)

# # 判断正数、负数或零的程序：
# num = float(input("请输入一个数字："))
# if num > 0:
#    print("输入的数字是正数")
# elif num == 0:
#    print("输入的数字是零")
# else:
#    print("输入的数字是负数")
#
# #求年龄最大和最小值的程序：
# age1 = int(input("请输入第一个人的年龄："))
# age2 = int(input("请输入第二个人的年龄："))
# age3 = int(input("请输入第三个人的年龄："))
# max_age = max(age1, age2, age3)
# min_age = min(age1, age2, age3)
# print(f"年龄最大的人是{max_age}岁，年龄最小的人是{min_age}岁。")

#显示一天名称的程序
# day = int(input("请输入1到7之间的数字："))
# if day == 1:
#     print("周日")
# elif day == 2:
#     print("周一")
# elif day == 3:
#     print("周二")
# elif day == 4:
#     print("周三")
# elif day == 5:
#     print("周四")
# elif day == 6:
#     print("周五")
# elif day == 7:
#     print("周六")
# else:
#     print("输入的数字不在1到7之间。")

# ***#dictionary 中删除指定items的tip---👉用for循环＋del
myfamily = {
  "child1" : {
    "name" : "Emil",
    "year" : 2004
  },
  "child2" : {
    "name" : "Tobias",
    "year" : 2007
  },
  "child3" : {
    "name" : "Linus",
    "year" : 2011
  }
}
for x, y in myfamily.items():
    del x, y['year']
    print(y)
#{'name': 'Emil'}
# {'name': 'Tobias'}
# {'name': 'Linus'}

# #Add Items-添加项目
set1 = {"apple","banana","cherry"}
# set1.add("orange")
# print(set1)
set1.update({"orange"})#加个大括号{}，放在小括号里面双引号外面就不会将orange分开
print(set1)
# #
thisset = {"apple","banana","cherry"}
tropical = {"pineapple","mango","papaya"}
thisset.update(tropical)
print(thisset)
# dictionary-元素不可重复，即键不可重复，新键会覆盖原值
dict1 ={"brand":"Ford",
        "model":"Mustang",#逗号勿漏
        "year":1964,
        "year":2022,
        }
print(dict1)
# key-value；键值对  键不可重复，一个键可对应多个值
dict1 ={"brand":"Ford",
        "model":"Mustang",#逗号勿漏
        "year":1964,
        }
print(dict1["brand"])
# print(dict1[0])#KeyError: 0错误原因没有0键，修改方法，把year改为0这个键就会输出1964

def my_func(a, b, c):
    print(a, b, c)
my_tuple = (1, 2, 3)
my_dict = {'a': 1, 'b': 2, 'c': 3}
my_func(*my_tuple)
# 输出：1 2 3是元组
my_func(**my_dict)
# 输出：1 2 3是字典